function myCreate(obj){
    function C(){}
    C.prototype = obj;
    return new C();
}

/**
 * 手写new函数
 * 1. 创建一个空对象
 * 2. 将空对象的原型指向构造函数原型
 * 3. 将空对象作为构造函数的上下文
 * @param fn
 * @param args
 * @returns {{}}
 */
function myNew(fn,...args){
    let obj = {};
    Object.setPrototypeOf(obj,fn.prototype);
    fn.apply(obj,args);
    return obj;
}

function mySleep(delay){
    return new Promise((resolve) => {
        setTimeout(()=>{
            return resolve()
        },delay)
    })
}


function myAjax(config){
    let _ = Object.assign({
        methods:'GET',
        url: 'www.baidu.com',
        data: '',
    },config);
    return new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest, sendData = "";
        if(_.data){
            for(let i in _.data){
                sendData += `&${i}=${_.data[i]}`
            }
        }
        let url = sendData ? `${config.url}?${sendData}` : config.url;
        if(_.methods === 'GET'){
            xhr.open("GET",url,true);
            xhr.send(sendData);
        }
        if(_.methods === 'POST'){
            xhr.open("OPEN", config.url,true);
            xhr.send(sendData.slice(1))
        }
        xhr.onreadystatechange = function(){
            if(xhr.readyState === 4){

            }
        }
    })
}
